package cn.gjxblog.scheduling.jdk.executor;

import cn.gjxblog.base.LogUtils;

import java.util.Random;

public class MyRunableTask implements Runnable {
    /**
     * 作业名
     */
    private String name;

    public MyRunableTask(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        long start = System.currentTimeMillis();

        System.out.println(LogUtils.getThreadInfo()+"作业"+name+"正在执行~~");
        try {
            Random random = new Random();
            Thread.sleep(1000*(random.nextInt(5)+1));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();

        System.out.println(LogUtils.getThreadInfo()+"作业"+name+"执行结束~~ 共执行"+(end-start)/1000+"秒");

    }

}
